﻿using UnityEngine;
using System.Collections;

public class BeanTarget : MonoBehaviour
{

    private bool putBean;

    void Start ()
    {
        
        StartCoroutine ("PutBeans");
    }

    void Update ()
    {
        if (putBean)
        {
            Instantiate (GameController.gameController.prefabBean, this.transform.position, this.transform.rotation);
            putBean = false;
        }
    }

    public void PutBean (Vector3 position)
    {
        this.transform.position = position;
        putBean = true;
    }

    //每帧放一个豆子
    IEnumerator PutBeans ()
    {
        int x;
        for (x = 0; x <= GameController.gameController.maxWidth; x++)
        {
            PutBean (new Vector3 (x, 0, this.transform.position.z));
            yield return 0;
        }
        Destroy (this.gameObject);
    }
}
